/**
 * @brief Macro.h
 */

#ifndef MACRO_H_
#define MACRO_H_

#include <cmath>
#include <cstdlib>

inline float randomfloat() { return float(rand()) / RAND_MAX; }
inline float randomfloat(const float& start, const float& end)
{
  return ( (end-start) * (float(rand()) / RAND_MAX) + start );
}

//float a =-0.67;
//float b=3.5;
//srand(time(NULL));
//
//for(int i=0; i<10;i++){
// x=((b-a)*((float)rand()/RAND_MAX))+a;
//cout<< "x="<<x<<endl;}

// normaldistribution return random value
// m=mean s=sigma standard deviation N(my,sigma)
inline double normalDistribution(const double& m, const double& s)
{
    double x1, x2, w, y1;
    static double y2;
    static int use_last = 0;

    if (use_last)
    {
        y1 = y2;
        use_last = 0;
    }
    else
    {
        do
        {
            x1 = 2.0 * randomfloat() - 1.0;
            x2 = 2.0 * randomfloat() - 1.0;
            w = x1 * x1 + x2 * x2;
        }
        while (w >= 1.0);

        w = sqrt((-2.0 * log(w)) / w);
        y1 = x1 * w;
        y2 = x2 * w;
        use_last = 1;
    }

    return m + y1 * s;
}

#endif /* MAKRO_H_ */
